package generator;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.util.HashMap;


public class generator {

    public static void main(String[] args) {
        String pkgPath = System.getProperty("user.dir") + "/mp-generator/src/main/java";
        String mappPath = System.getProperty("user.dir") + "/mp-generator/src/main/java/mapper/xml";
        System.out.println(pkgPath);
        FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/mk?serverTimezone=UTC", "root", "123")
                .globalConfig(builder -> {
                    builder.author("Allen") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(pkgPath)// 指定输出目录
                            .disableOpenDir()
                            .commentDate("yyyy-MM-dd");
                })
                .packageConfig(builder -> {
                    builder.parent("com.allen.mk.template")// 设置父包名
                            .entity("pojo.entity")
                            .pathInfo(new HashMap<OutputFile,String>(){{
                                put(OutputFile.mapperXml,mappPath);
                            }}); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addTablePrefix("t_", "c_")// 设置过滤表前缀
                            .entityBuilder().enableLombok()
                            .logicDeleteColumnName("is_delete").enableRemoveIsPrefix()
                            .enableTableFieldAnnotation()
                            .mapperBuilder()
                            .enableMapperAnnotation()
                            .serviceBuilder().formatServiceFileName("%sService")
                            .controllerBuilder().enableRestStyle();
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

}
